# 需求：使用cookie实现跳过登录
# 1). 手动登录淘宝，获取cookie
# 2). 使用获取到的cookie，达到登录目的，然后就可以执行登录之后的操作
# 导入控制浏览器和时间的模块
from selenium import webdriver
import time

# 创建Chrome浏览器实例
driver = webdriver.Chrome()

# 先打开淘宝首页（必须先访问，否则添加Cookie会报错）
driver.get("https://www.taobao.com")

# 登录状态的Cookie列表（需替换成自己的有效Cookie）
cookies = [
    {"name": "_m_h5_tk", "value": "8127536050c0b7ec428c9175bbcd7e95_1761912065255"},
    {"name": "_m_h5_tk_enc", "value": "c384ba012629fb5bc53f6b34a0c8a338"},
    {"name": "cookie2", "value": "176a2cbfb55a9712b67889825c099081"},
    {"name": "cna", "value": "2W+LIT10wF4CAXQEYMs4zi1u"},
    {"name": "uc1", "value": "cookie15=UIHiLt3xD8xYTw%3D%3D&existShop=false&cookie21=URm48syIYn73&cookie14=UoYY4vIPyn6tuQ%3D%3D&pas=0&cookie16=W5iHLLyFPlMGbLDwA%2BdvAGZqLg%3D%3D"},
    {"name": "lgc", "value": "%5Cu66FE%5Cu79BB%5Cu5BAB"},
    {"name": "tracknick", "value": "%5Cu66FE%5Cu79BB%5Cu5BAB"},
    {"name": "isg", "value": "BP39iIc-SBgpfez0rixOocUgDFn3mjHs12zmw79COdSD9h0oh-pBvMuloCqwwkmk"},
]

# 把Cookie添加到浏览器
for cookie in cookies:
    driver.add_cookie(cookie)

# 刷新页面让Cookie生效，等待5秒加载
driver.refresh()
time.sleep(5)

# 关闭浏览器
driver.quit()